package 实验9;

import java.util.Date;
class IllegalTriangleException extends Exception{
	//自定义的异常类
	public IllegalTriangleException() {
		super("不合法的三角形");
	}
}

public class Triangle extends GeometricObject{
	
	public static void main(String[] args) throws IllegalTriangleException {
		//主方法中试图构造边长为 1 2 3 的三角形   出现异常  被catsh捕获并打印出栈轨迹
			Triangle triangle = new Triangle(1,2,3);
	}
	
	private double side1,side2,side3;
	public Triangle() {
		side1 = 1.0;
		side2 = 1.0;
		side3 = 1.0;
	}
	public Triangle(double side1 ,double side2 ,double side3) throws IllegalTriangleException{
		if(side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1) {
			throw new IllegalTriangleException();
		}
		this.side1 = side1;
		this.side2 = side2;
		this.side3 = side3;
	}
	public double getPerimeter() {
		return side1 + side2 + side3;
	}
	public double getArea() {
		double p = getPerimeter() / 2;
		return Math.sqrt(p*(p-side1)*(p-side2)*(p-side3));
	}
	@Override
	public String toString() {
		return "周长："
				+ getPerimeter() + "\n面积：" + getArea() + "\n颜色："+ getColor()+"\n是否填充"+isFilled();
	}

}
class GeometricObject{
	private String color;
	private boolean filled;
	private Date dateCreated;
	public GeometricObject() {
		dateCreated = new Date();
	}
	public GeometricObject(String color ,boolean filled) {
		this.color = color;
		this.filled = filled;
		dateCreated = new Date();
	}
	public String getColor() {
		return color;
	}
	public void setColor(String color) {
		this.color = color;
	}
	public boolean isFilled() {
		return filled;
	}
	public void setFilled(boolean filled) { 
		this.filled = filled;
	}
	public Date getDateCreated() {
		return dateCreated;
	}
	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}
	@Override
	public String toString() {
		return "创建于：" + dateCreated + "\n颜色："+color+"\n是否填充：" +filled;
	}
}
